package za.ac.wits.was.courses.allocations;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.Transient;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import za.ac.wits.was.courses.Course;
import za.ac.wits.was.user.model.AcademicStaff;

/**
 *
 * @author Salman Noor : School of Electrical and Information Engineering
 * @Copyright: Wits University 2013 - All Rights Reserved
 * @email: salmannoor74415@gmail.com
 * @License: BSD License (http://www.linfo.org/bsdlicense.html)
 */
@Entity
@Table(name = "course_allocations")
public class CourseAllocations implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "course_allocation_id")
    private Long course_allocation_id;
    
    @ManyToOne
    @JoinColumn(name = "user_id")
    private AcademicStaff academic_staff_member;
    
    @Column(name = "pending")
    private Boolean pending;
    
    @Column(name = "approved")
    private Boolean approved;
    
    @Column(nullable = false)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date start_date;
    
    @ManyToOne
    @JoinColumn(name = "course_id")
    private Course course;

    @Transient
    private String status;
        
    public Long getCourse_allocation_id() {
        return course_allocation_id;
    }

    public void setCourse_allocation_id(Long course_allocation_id) {
        this.course_allocation_id = course_allocation_id;
    }

    public AcademicStaff getAcademic_staff_member() {
        return academic_staff_member;
    }

    public void setAcademic_staff_member(AcademicStaff academic_staff_member) {
        this.academic_staff_member = academic_staff_member;
    }

    public Boolean getPending() {
        return pending;
    }

    public void setPending(Boolean pending) {
        this.pending = pending;
    }

    public Boolean getApproved() {
        return approved;
    }

    public void setApproved(Boolean approved) {
        this.approved = approved;
    }

    public Date getStart_date() {
        return start_date;
    }

    public void setStart_date(Date start_date) {
        this.start_date = start_date;
    }

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }
    @JsonProperty("status")
    public String getStatus() {
        if (this.pending) {
            this.status = "Pending";
        } else {
            if (this.approved) {
                this.status = "Approved";
            } else {
                this.status = "Declined";
            }
        }
        return status;
    }
    
    @JsonIgnore
    public void setStatus(String status) {
        this.status = status;
    }
    
}
